package reflect;

import java.io.File;
import java.lang.reflect.Field;

/**
 * 访问属性
 */
public class ReflectDemo7 {
    public static void main(String[] args) throws Exception {
        Class cls=Class.forName("reflect.Teacher");
        Object obj=cls.newInstance();
        Field field=cls.getField("name");
        field.set(obj,"范丞丞");//obj.name='范丞丞';
        System.out.println(obj);

        //暴力反射
        Object obj1=cls.newInstance();
        Field field1=cls.getDeclaredField("age");
        field1.setAccessible(true);
        field1.set(obj1,90);
        System.out.println(obj1);
        field1.setAccessible(false);

    }
}
